#include<iostream>
using namespace std;

#include<vector>

int minFallingPathSum(vector<vector<int>>& matrix) {
	int length1 = matrix.size(), length2 = matrix[0].size();
	vector<int> temp(length2 + 1, 0);
	vector<vector<int>> nums(length1 + 1, temp);

	for (int i = 0; i <=length1; i++)
	{
		for (int j = 0; j <=length2; j++)
		{
			if (i == 0 || j == 0)
			{
				nums[i][j] = 0;
			}
			else
			{
				
				if (j < length2)
				{
					if (j == 1)
					{
						nums[i][j] = min(nums[i - 1][j], nums[i - 1][j + 1]) + matrix[i - 1][j - 1];
					}
					else
					{
						nums[i][j] = min(nums[i - 1][j], min(nums[i - 1][j - 1], nums[i - 1][j + 1])) + matrix[i - 1][j - 1];
					}
					
				}
				else
				{
					nums[i][j] = min(nums[i - 1][j], nums[i - 1][j - 1]) + matrix[i - 1][j - 1];
				}
			}
		}
	}
	int minNumber = nums[length1][1];
	for (int j = 1; j <= length2; j++)
	{
		if (minNumber > nums[length1][j])
		{
			minNumber = nums[length1][j];
		}
	}

	return minNumber;
}


int main()
{
	vector<vector<int>> matrix = { {-48} };

	cout<<minFallingPathSum(matrix)<<endl;
}